#include "teditwidget.h"
#include <QPushButton>
#include <QTextEdit>
#include "tserialize.h"
#include "tclientserver.h"
TEditWidget::TEditWidget(QWidget *parent)
    : QWidget(parent)
    , m_pSendButton(new QPushButton(this))
    , m_pTextEdit(new QTextEdit(this))
{
    resize(600,250);
    setAttribute(Qt::WA_StyledBackground, true);
    setStyleSheet("TEditWidget{background:#19D7D0;}");
    initButton();
    connect(m_pSendButton,&QPushButton::released,this,&TEditWidget::onSendButtonReleased);
}

TEditWidget::~TEditWidget()
{}

void TEditWidget::onSendButtonReleased()
{
    QString str = m_pTextEdit->toPlainText();
    qDebug() << str;
    TClientServer::Instance()->m_pSocket->write(TSerialize::serialize(OPERATOR::SEND_MESSAGE,str.toUtf8()));
    m_pTextEdit->clear();
}

void TEditWidget::initButton()
{
    m_pSendButton->resize(60,25);
    m_pSendButton->move(535,220);
    m_pSendButton->setText("send");
    m_pSendButton->raise();

    m_pTextEdit->resize(590,220);
    m_pTextEdit->move(5,30);
    m_pTextEdit->setStyleSheet("QTextEdit{background:#d323c5;}");
}
